package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportTaskReply;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportTaskReplyDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2020-05-20 17:34:42
 */
public class TransportTaskReplyConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportTaskReplyConverts.class);

    public static List<TransportTaskReplyDTO> convert(List<TransportTaskReply> transportTaskReplyList) {
        if (CollectionUtils.isEmpty(transportTaskReplyList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportTaskReplyDTO> transportTaskReplyListResult = Lists.newArrayList();
        for (TransportTaskReply transportTaskReply : transportTaskReplyList) {
            transportTaskReplyListResult.add(convert(transportTaskReply));
        }
        return transportTaskReplyListResult;
    }

    public static TransportTaskReplyDTO convert(TransportTaskReply transportTaskReply) {
        try {
            return BeanUtils.copy(transportTaskReply, TransportTaskReplyDTO.class);
        } catch (Exception e) {
            LOG.error("TransportTaskReply到TransportTaskReplyDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportTaskReply到TransportTaskReplyDTO转换失败", e);
        }
    }

    public static TransportTaskReply convert(TransportTaskReplyDTO transportTaskReplyDTO) {
        try {
            return BeanUtils.copy(transportTaskReplyDTO, TransportTaskReply.class);
        } catch (Exception e) {
            LOG.error("TransportTaskReplyDTO到TransportTaskReply转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportTaskReplyDTO到TransportTaskReply转换失败", e);
        }
    }
}